import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ScreenAdapter {
  static void init(BuildContext context) {
    ScreenUtil.init(
      context,
      designSize: const Size(375, 812), // iPhone X设计尺寸
      minTextAdapt: true,
      splitScreenMode: true,
    );
  }

  // 宽度适配
  static double width(double width) => width.w;

  // 高度适配
  static double height(double height) => height.h;

  // 字体大小适配
  static double fontSize(double fontSize) => fontSize.sp;

  // 半径适配
  static double radius(double radius) => radius.r;

  // 获取屏幕宽度
  static double get screenWidth => 1.sw;

  // 获取屏幕高度
  static double get screenHeight => 1.sh;

  // 获取状态栏高度
  static double get statusBarHeight => ScreenUtil().statusBarHeight;

  // 获取底部安全区域高度
  static double get bottomBarHeight => ScreenUtil().bottomBarHeight;

  // 判断是否为平板
  static bool get isTablet => screenWidth > 600;

  // 判断是否为桌面端
  static bool get isDesktop => screenWidth > 1024;

  // 获取适配后的边距
  static EdgeInsets padding({
    double? all,
    double? horizontal,
    double? vertical,
    double? top,
    double? bottom,
    double? left,
    double? right,
  }) {
    return EdgeInsets.only(
      top: (top ?? vertical ?? all ?? 0).h,
      bottom: (bottom ?? vertical ?? all ?? 0).h,
      left: (left ?? horizontal ?? all ?? 0).w,
      right: (right ?? horizontal ?? all ?? 0).w,
    );
  }

  // 获取适配后的圆角
  static BorderRadius borderRadius({
    double? all,
    double? topLeft,
    double? topRight,
    double? bottomLeft,
    double? bottomRight,
  }) {
    return BorderRadius.only(
      topLeft: Radius.circular((topLeft ?? all ?? 0).r),
      topRight: Radius.circular((topRight ?? all ?? 0).r),
      bottomLeft: Radius.circular((bottomLeft ?? all ?? 0).r),
      bottomRight: Radius.circular((bottomRight ?? all ?? 0).r),
    );
  }

  // 获取适配后的尺寸
  static Size size(double width, double height) {
    return Size(width.w, height.h);
  }

  // 获取适配后的偏移
  static Offset offset(double dx, double dy) {
    return Offset(dx.w, dy.h);
  }
}

